package com.reform.controller.common;


import com.reform.pojo.teacher.TeacherLoginParams;
import com.reform.res.Result;
import com.reform.service.ITeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

@Api(tags = "LoginController")
@RestController
public class LoginController {

    @Autowired
    ITeacherService teacherService;

    @ApiOperation(value = "测试")
    @GetMapping("/test")
    public String hello() {
        return "Hello to Reform!123";
    }

    @ApiOperation(value = "登录之后返回token")
    @PostMapping("/login")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gh", value = "工号", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "password", value = "密码", paramType = "query", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "type", value = "类型", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result login(TeacherLoginParams teacherLoginParams) throws SQLException {
        //登录
        return teacherService.login(teacherLoginParams.getGh(), teacherLoginParams.getPassword(), teacherLoginParams.getType());
    }

    @ApiOperation(value = "切换身份")
    @PostMapping("/changeIdentity")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result changeIdentity(HttpServletRequest request, Integer type) throws SQLException {
        //切换身份
        return teacherService.changeIdentity(request, type);
    }

}
